package storage;

import javax.microedition.rms.RecordFilter;

/**
 * Implementation of RecordFilter for Persistent classes
 * 
 * @author Marcelo Gatto
 */
public abstract class PersistentFilter implements RecordFilter {

	private Class persistentType;
	
	/**
	 * Injected by PersistentDAO
	 */
	public void setPersistentType(Class perType) {
		persistentType = perType;
	}
	
	public boolean matches(byte[] bts) {
		if(persistentType==null) return false;
		try {
			Persistent per = (Persistent) persistentType.newInstance();
			per.resurrect(bts);
			return matches(per);
		} catch (Exception e) {
			return false;
		}
	}
	
	public abstract boolean matches(Persistent persistent);
	
}